package com.ctsi.ssdc.service.impl;

import com.ctsi.ssdc.entity.Excel02;
import com.ctsi.ssdc.mapper.Excel02Mapper;
import com.ctsi.ssdc.service.Excel02Service;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Future;

/**
 * 2分区镇一般公共预算收入(Excel02)表服务实现类
 *
 * @author makejava
 * @since 2023-02-20 13:03:32
 */
@Service("excel02Service")
public class Excel02ServiceImpl implements Excel02Service {
    @Resource
    private Excel02Mapper excel02Dao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Excel02 queryById(Long id) {
        return this.excel02Dao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param excel02     筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<Excel02> queryByPage(Excel02 excel02, PageRequest pageRequest) {
        long total = this.excel02Dao.count(excel02);
        return new PageImpl<>(this.excel02Dao.queryAllByLimit(excel02, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param excel02 实例对象
     * @return 实例对象
     */
    @Override
    public Excel02 insert(Excel02 excel02) {
        this.excel02Dao.insert(excel02);
        return excel02;
    }

    /**
     * 修改数据
     *
     * @param excel02 实例对象
     * @return 实例对象
     */
    @Override
    public Excel02 update(Excel02 excel02) {
        this.excel02Dao.update(excel02);
        return this.queryById(excel02.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.excel02Dao.deleteById(id) > 0;
    }

    /**
     *  批量添加数据
     * @param list
     * @return 是否成功
     */
    @Override
    public boolean insertBatch(List<Excel02> list) {
        return excel02Dao.insertBatch(list)>0;
    }

    @Override
    public List<Excel02> queryByTime(int year, int month) {
        return excel02Dao.queryByTime(year, month);
    }

    /**
     * 根据日期删除
     * @param date
     * @return 是否成功
     */
    @Override
    public boolean removeByDate(Date date) {
        return excel02Dao.removeByDate(date);
    }
}
